from datastruct import ListNode
def list_len(head:ListNode)->int:
    count = 0
    while head is not None:
        count+=1 
        head = head.next
    return count

def same_list(list1:ListNode,list2:ListNode)->int:
    flag = False
    if list_len(list1) != list_len(list2):
        flag = False
    while list1 is not None and list2 is not None and list1.val == list2.val:
        list1 = list1.next
        list2 = list2.next

    return list1 is None and list2 is None

